using Gateway.IApplication.BaseInput;
using Gateway.IApplication.DataDic;
using Gateway.IApplication.DataDic.Input;
using Gateway.IQuery;
using Gateway.IQuery.DataDic;
using Gateway.IQuery.DataDic.Request;
using Gateway.IQuery.DataDic.Result;

namespace Gateway.UI.Api.Controllers;

/// <summary>
/// 数据字典服务
/// </summary>
public class DataDicController : BaseController
{
    private readonly IDataDicApp _dataDicApp;
    private readonly IDataDicQuery _dataDicQuery;

    /// <summary>
    /// 
    /// </summary>
    public DataDicController(IDataDicApp dataDicApp, IDataDicQuery dataDicQuery)
    {
        _dataDicApp = dataDicApp;
        _dataDicQuery = dataDicQuery;
    }

    /// <summary>
    /// 创建
    /// </summary>
    /// <param name="input"></param>
    /// <returns>返回主键标识</returns>
    [HttpPost, Route("add")]
    public async Task<string> Add(CreateDataDicInput input)
    {
        return await _dataDicApp.Add(input);
    }

    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("update")]
    public async Task<bool> Update(UpdateDataDicInput input)
    {
        return await _dataDicApp.Update(input);
    }

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("remove")]
    public async Task<bool> Remove(RemoveInput input)
    {
        return await _dataDicApp.Remove(input);
    }

    /// <summary>
    /// 启用/禁用
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    [HttpPost, Route("Disable")]
    public async Task<bool> Disable(DisableInput input)
    {
        return await _dataDicApp.Disable(input);
    }

    /// <summary>
    /// 获取分页列表
    /// </summary>
    /// <returns></returns>
    [HttpPost, Route("list/page")]
    public async Task<PageResult<DataDicDetailResult>> GetPageList(DataDicPageRequest request)
    {
        return await _dataDicQuery.GetList(request);
    }

    /// <summary>
    /// 获取列表-所有数据
    /// </summary>
    /// <returns></returns>
    [HttpGet, Route("list/all")]
    public async Task<List<DataDicDetailResult>> GetAll()
    {
        return await _dataDicQuery.GetAll();
    }

    /// <summary>
    /// 获取列表-根据code  相邻子级
    /// </summary>
    /// <returns></returns>
    [HttpGet, Route("list/byCode")]
    public async Task<List<DataDicDetailResult>> GetListByCode(string code)
    {
        return await _dataDicQuery.GetListByCode(code);
    }

    /// <summary>
    /// 获取category 类型的树形
    /// </summary>
    /// <returns></returns>
    [HttpPost, Route("tree")]
    public async Task<List<DataDicCategoryTreeResult>> GetCategoryTree()
    {
        return await _dataDicQuery.GetCategoryList();
    }
}